//
//  InstallViewController.m
//  YYPHSpeedJump
//
//  Created by speedjump on 15/12/29.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "InstallViewController.h"
#import "PasswordTextField.h"
#import "PersonCenter.h"
#import "InstallTableViewCell.h"
@interface InstallViewController ()<UIAlertViewDelegate>
@property (nonatomic, strong) NSString *urlStr;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation InstallViewController


- (NSMutableArray*)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithObjects:@"个人中心",@"清除缓存", nil];
    }
    return _dataArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addSubViews];
    self.view.backgroundColor = kColors(239, 239, 244, 1);
    self.navigationItem.title =@"设置";
    
}
//清除缓存

- (void)addSubViews
{
    
    self.installTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200) style:UITableViewStylePlain];
    self.installTabelView.delegate = self;
    self.installTabelView.dataSource = self;
    self.installTabelView.scrollEnabled = NO;
    self.installTabelView.backgroundColor = [UIColor clearColor];
    [self.installTabelView registerNib:[UINib nibWithNibName:@"InstallTableViewCell" bundle:nil] forCellReuseIdentifier:@"InstallCell"];
    [self.view addSubview:self.installTabelView];
    UILabel *weLable = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-160)/2,kScreenHeight-250-64, 160, 30)];
    weLable.backgroundColor = [UIColor clearColor];
    weLable.text =@"联系我们";
    weLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:weLable];
    UILabel *phoneLable = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2,kScreenHeight-220-64, 200, 30)];
    phoneLable.backgroundColor = [UIColor clearColor];
    phoneLable.text = @"电话:010-84760633";
    phoneLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:phoneLable];
    UILabel *QQlabel = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2,kScreenHeight-190-64, 200, 30)];
    QQlabel.backgroundColor = [UIColor clearColor];
    QQlabel.text = @"QQ群:417786992";
    QQlabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:QQlabel];
    UIButton *exitBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    exitBtn.frame = CGRectMake(15,kScreenHeight-160-64, kScreenWidth-30, 44);
    exitBtn.backgroundColor = kColors(218, 166, 46, 1);
    [exitBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    exitBtn.layer.cornerRadius = 5;
    [exitBtn addTarget:self action:@selector(exitAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:exitBtn];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    InstallTableViewCell *installCell =[tableView dequeueReusableCellWithIdentifier:@"InstallCell" forIndexPath:indexPath];
    installCell.functionLable.text = self.dataArr[indexPath.row];
    installCell.selectionStyle =UITableViewCellSelectionStyleNone;
    if (indexPath.row ==1)
    {
        NSString *path = [NSString stringWithFormat:@"%@/default", kCachePath];
        // [Tools clearCache:path];
        
        CGFloat size = [Tools folderSizeAtPath:path];
        installCell.assistLable.text = [NSString stringWithFormat:@"%.2fM",size];
    }
    return installCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 52;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        PersonCenter *personCenter = [[PersonCenter alloc]init];
        [self.navigationController pushViewController:personCenter animated:YES];
    }
    if (indexPath.row ==1) {
        NSString *path = [NSString stringWithFormat:@"%@/default", kCachePath];
        [Tools clearCache:path];
        // NSLog(@"%@",kCachePath);
        CGFloat size = [Tools folderSizeAtPath:path];
        InstallTableViewCell *cell;
         cell.assistLable.text= [NSString stringWithFormat:@"%.2fM", size];
        [self.installTabelView reloadData];

    }
}
//点击退出登录
- (void)exitAction
{
    NSString*appDomain = [[NSBundle mainBundle]bundleIdentifier];
    
    [[NSUserDefaults standardUserDefaults]removePersistentDomainForName:appDomain];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirst"];
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [app setRootVC];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.urlStr]];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
